package huixue.cn.com.library.util;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;


import huixue.cn.com.library.app.BaseApplication;

/**
 * Created by wangsai on 2016/4/19.
 */
public class PixelUtils {

    /**
     * 获得屏幕高度
     *
     * @return
     */
    public static int getScreenWidth() {
        WindowManager wm = (WindowManager) BaseApplication.getApplictionContext()
                .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.widthPixels;
    }

    /**
     * 获得屏幕宽度
     *
     * @return
     */
    public static int getScreenHeight() {
        WindowManager wm = (WindowManager) BaseApplication.getApplictionContext()
                .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.heightPixels;
    }

    public static int dp2px(float value) {
        final float scale = BaseApplication.getApplictionContext().getResources().getDisplayMetrics().density;
        return (int) (value * scale + 0.5f);
    }

    public static int px2dp(float value) {
        final float scale = BaseApplication.getApplictionContext().getResources().getDisplayMetrics().density;
        return (int) (value / scale + 0.5f);
    }
}
